#!/usr/bin/env python

import sys
import colorama
import logging.config

from _app import App
from _meta import Meta

class Console(App):
    '''Console class

    @author Julot <andy.julot@gmail.com>
    @since Sunday, January 15, 2012. 05:05 PM'''

    def __init__(self):
        colorama.init(autoreset=True)

    def __del__(self):
        colorama.deinit()

    def success(self, message):
        sys.stdout.write(colorama.Fore.GREEN + colorama.Style.BRIGHT + message)
        
    def progress(self, message):
        sys.stdout.write(colorama.Fore.CYAN + colorama.Style.BRIGHT + message)
        
    def warning(self, message):
        sys.stdout.write(colorama.Fore.YELLOW + colorama.Style.BRIGHT + message)
        
    def fail(self, message):
        sys.stdout.write(colorama.Fore.RED + colorama.Style.BRIGHT + message)
    
    def info(self, message):
        sys.stdout.write(colorama.Fore.WHITE + colorama.Style.BRIGHT + message)
        
    def ask(self, message):
        s = colorama.Fore.WHITE + colorama.Style.BRIGHT + '%s [yes|no] '
        return raw_input(s % message)[0].lower() == 'y'
                          
    def greeting(self, meta):
        self.warning('%s - %s\n' % (meta.name, meta.description))
        self.warning('Version %s\n' % meta.long_version)
        date = meta.release_date.strftime("%A, %B %d, %Y")
        self.warning('Released at %s\n\n' % date)

    def run(self):
        meta = Meta()
        self.greeting(meta)
        self.initLogging(meta.name.lower())
        self.initConfig(meta.name.lower(), {'Section': {'Key': 'Value'}})
        logging.info('%s started.' % meta.name)
        
        self.warning('\nGood bye ^_^v\n')
        logging.info('%s shut down.\n' % meta.name)
        